﻿
namespace SPL.Windows.Forms
{
	/// <summary>
	/// This is the abstract edit form for the <see cref="Entities.User"/> entity.
	/// </summary>
	/// <remarks>This class is overwritten by .netTiers at each generation.</remarks>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class UserEditControlBase : System.Windows.Forms.UserControl
	{
		#region Fields
		
		//private System.Windows.Forms.TableLayoutPanel uxTableLayoutPanel;
		/// <summary>
		/// The ErrorProvider for the Entity;
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxErrorProvider;
		
		/// <summary>
		/// The BindingSource for the entity.
		///</summary>
		protected System.Windows.Forms.BindingSource uxBindingSource;
						
		
		/// <summary>
		/// TextBox for the Id property. 
		/// </summary>
		protected System.Windows.Forms.TextBox uxId;
		
		/// <summary>
		/// The <see cref="System.Windows.Forms.Label"/> associated with the Id property.
		/// </summary>
		protected System.Windows.Forms.Label uxIdLabel;
		
		/// <summary>
		/// TextBox for the Username property. 
		/// </summary>
		protected System.Windows.Forms.TextBox uxUsername;
		
		/// <summary>
		/// The <see cref="System.Windows.Forms.Label"/> associated with the Username property.
		/// </summary>
		protected System.Windows.Forms.Label uxUsernameLabel;
		
		/// <summary>
		/// ComboBox for the DeptId property.
		/// </summary>
		protected System.Windows.Forms.ComboBox uxDeptId;
		
		/// <summary>
		/// The <see cref="System.Windows.Forms.Label"/> associated with the DeptId property.
		/// </summary>
		protected System.Windows.Forms.Label uxDeptIdLabel;
		
		/// <summary>
		/// ComboBox for the RoleId property.
		/// </summary>
		protected System.Windows.Forms.ComboBox uxRoleId;
		
		/// <summary>
		/// The <see cref="System.Windows.Forms.Label"/> associated with the RoleId property.
		/// </summary>
		protected System.Windows.Forms.Label uxRoleIdLabel;
		
		/// <summary>
		/// CheckBox for the IsActive property.
		/// </summary>
		protected System.Windows.Forms.CheckBox uxIsActive;
		
		/// <summary>
		/// The <see cref="System.Windows.Forms.Label"/> associated with the IsActive property.
		/// </summary>
		protected System.Windows.Forms.Label uxIsActiveLabel;
		
		/// <summary>
		/// TextBox for the Password property. 
		/// </summary>
		protected System.Windows.Forms.TextBox uxPassword;
		
		/// <summary>
		/// The <see cref="System.Windows.Forms.Label"/> associated with the Password property.
		/// </summary>
		protected System.Windows.Forms.Label uxPasswordLabel;
		#endregion
		
		#region Main entity
		private Entities.User _User;
		/// <summary>
		/// Gets or sets the <see cref="Entities.User"/> entity to edit with this form.
		/// </summary>
		/// <value>The <see cref="Entities.User"/> instance.</value>
		public Entities.User User
		{
			get {return this._User;}
			set
			{
				this._User = value;
				if (value != null) 
				{
					this.uxBindingSource.DataSource = value;
					BindControls();
				}			
				
			}
		}
		#endregion
		
		/// <summary>
		/// Binds the controls.
		/// </summary>
		private void BindControls()
		{
			this.uxId.DataBindings.Clear();
			this.uxId.DataBindings.Add("Text", this.uxBindingSource, "Id", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
			this.uxUsername.DataBindings.Clear();
			this.uxUsername.DataBindings.Add("Text", this.uxBindingSource, "Username", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
			this.uxDeptId.DataBindings.Clear();
			this.uxDeptId.DataBindings.Add("SelectedValue", this.uxBindingSource, "DeptId", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
			this.uxRoleId.DataBindings.Clear();
			this.uxRoleId.DataBindings.Add("SelectedValue", this.uxBindingSource, "RoleId", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
			this.uxIsActive.DataBindings.Clear();
			this.uxIsActive.DataBindings.Add("Checked", this.uxBindingSource, "IsActive", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
			this.uxPassword.DataBindings.Clear();
			this.uxPassword.DataBindings.Add("Text", this.uxBindingSource, "Password", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
		}					
		
		#region Constructor
		
		/// <summary>
		/// Initializes a new instance of the <see cref="UserEditControlBase"/> class.
		/// </summary>
		public UserEditControlBase()
		{
			InitializeComponent();			
			
			this.uxBindingSource.CurrentItemChanged += new System.EventHandler(uxBindingSource_currentItemChanged);
		}		
		
		/// <summary>
		/// 
		/// </summary>
		private void uxBindingSource_currentItemChanged(object sender, System.EventArgs e)
		{
			if (_User != null) _User.Validate();
		}	
				
		/// <summary>
		/// Initializes the component.
		/// </summary>
		public void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.uxErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxBindingSource = new System.Windows.Forms.BindingSource(this.components);
			
			//this.uxTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
			this.uxId = new System.Windows.Forms.TextBox();
			uxIdLabel = new System.Windows.Forms.Label();
			this.uxUsername = new System.Windows.Forms.TextBox();
			uxUsernameLabel = new System.Windows.Forms.Label();
			this.uxDeptId = new System.Windows.Forms.ComboBox();
			uxDeptIdLabel = new System.Windows.Forms.Label();
			this.uxRoleId = new System.Windows.Forms.ComboBox();
			uxRoleIdLabel = new System.Windows.Forms.Label();
			this.uxIsActive = new System.Windows.Forms.CheckBox();
			uxIsActiveLabel = new System.Windows.Forms.Label();
			this.uxPassword = new System.Windows.Forms.TextBox();
			uxPasswordLabel = new System.Windows.Forms.Label();
			
			((System.ComponentModel.ISupportInitialize)(this.uxBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxErrorProvider)).BeginInit();
			this.SuspendLayout();
			
			// 
			// uxTableLayoutPanel
			// 
			//this.uxTableLayoutPanel.AutoSize = true;
			//this.uxTableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
			//this.uxTableLayoutPanel.ColumnCount = 2;
			//this.uxTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 120F));
			//this.uxTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 250F));
			//this.uxTableLayoutPanel.Location = new System.Drawing.System.Drawing.Point(3, 3);
			//this.uxTableLayoutPanel.Name = "uxTableLayoutPanel";
			//this.uxTableLayoutPanel.RowCount = 2;
			//this.uxTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
			//this.uxTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
			//this.uxTableLayoutPanel.Size = new System.Drawing.Size(450, 50);
			//this.uxTableLayoutPanel.TabIndex = 0;
			
			//
			// uxErrorProvider
			//
			this.uxErrorProvider.ContainerControl = this;
			this.uxErrorProvider.DataSource = this.uxBindingSource;
			
			//
			// uxIdLabel
			//
			this.uxIdLabel.Text = "Id:";
			this.uxIdLabel.Location = new System.Drawing.Point(3, 0);
			this.Controls.Add(this.uxIdLabel);
			//this.uxTableLayoutPanel.Controls.Add(this.uxIdLabel);			
			//
			// uxId
			//
			this.uxId.ReadOnly = true;
			//this.uxTableLayoutPanel.Controls.Add(this.uxId);
			this.uxId.Location = new System.Drawing.Point(160, 0);
			this.Controls.Add(this.uxId);
			//
			// uxUsernameLabel
			//
			this.uxUsernameLabel.Text = "Username:";
			this.uxUsernameLabel.Location = new System.Drawing.Point(3, 26);
			this.Controls.Add(this.uxUsernameLabel);
			//this.uxTableLayoutPanel.Controls.Add(this.uxUsernameLabel);			
			//
			// uxUsername
			//
			this.uxUsername.Width = 250;
			this.uxUsername.MaxLength = 50;
			//this.uxTableLayoutPanel.Controls.Add(this.uxUsername);
			this.uxUsername.Location = new System.Drawing.Point(160, 26);
			this.Controls.Add(this.uxUsername);
			//
			// uxDeptIdLabel
			//
			this.uxDeptIdLabel.Text = "DeptId:";
			this.uxDeptIdLabel.Location = new System.Drawing.Point(3, 52);
			this.Controls.Add(this.uxDeptIdLabel);
			//this.uxTableLayoutPanel.Controls.Add(this.uxDeptIdLabel);			
			//
			// uxDeptId
			//
			//this.uxTableLayoutPanel.Controls.Add(this.uxDeptId);
			this.uxDeptId.Location = new System.Drawing.Point(160, 52);
			this.Controls.Add(this.uxDeptId);
			//
			// uxRoleIdLabel
			//
			this.uxRoleIdLabel.Text = "RoleId:";
			this.uxRoleIdLabel.Location = new System.Drawing.Point(3, 78);
			this.Controls.Add(this.uxRoleIdLabel);
			//this.uxTableLayoutPanel.Controls.Add(this.uxRoleIdLabel);			
			//
			// uxRoleId
			//
			//this.uxTableLayoutPanel.Controls.Add(this.uxRoleId);
			this.uxRoleId.Location = new System.Drawing.Point(160, 78);
			this.Controls.Add(this.uxRoleId);
			//
			// uxIsActiveLabel
			//
			this.uxIsActiveLabel.Text = "IsActive:";
			this.uxIsActiveLabel.Location = new System.Drawing.Point(3, 104);
			this.Controls.Add(this.uxIsActiveLabel);
			//this.uxTableLayoutPanel.Controls.Add(this.uxIsActiveLabel);			
			//
			// uxIsActive
			//
			//this.uxTableLayoutPanel.Controls.Add(this.uxIsActive);
			this.uxIsActive.Location = new System.Drawing.Point(160, 104);
			this.Controls.Add(this.uxIsActive);
			//
			// uxPasswordLabel
			//
			this.uxPasswordLabel.Text = "Password:";
			this.uxPasswordLabel.Location = new System.Drawing.Point(3, 130);
			this.Controls.Add(this.uxPasswordLabel);
			//this.uxTableLayoutPanel.Controls.Add(this.uxPasswordLabel);			
			//
			// uxPassword
			//
			this.uxPassword.Width = 250;
			this.uxPassword.MaxLength = 50;
			//this.uxTableLayoutPanel.Controls.Add(this.uxPassword);
			this.uxPassword.Location = new System.Drawing.Point(160, 130);
			this.Controls.Add(this.uxPassword);
			//
			// uxRoleId
			//				
			this.uxRoleId.DisplayMember = "Name";	
			this.uxRoleId.ValueMember = "Id";	
			//
			// uxDeptId
			//				
			this.uxDeptId.DisplayMember = "Name";	
			this.uxDeptId.ValueMember = "Id";	
			// 
			// UserEditControlBase
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			//this.Controls.Add(this.uxTableLayoutPanel);
			this.AutoScroll = true;
			this.Name = "UserEditControlBase";
			this.Size = new System.Drawing.Size(478, 311);
			//this.Localizable = true;
			((System.ComponentModel.ISupportInitialize)(this.uxErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxBindingSource)).EndInit();			
			this.ResumeLayout(false);
			this.PerformLayout();
		}
		#endregion
				
		#region ComboBox List
		
				
		private Entities.TList<Entities.Role> _RoleIdList;
		
		/// <summary>
		/// The ComboBox associated with the RoleId property.
		/// </summary>
		[System.ComponentModel.Category("ComboBox BindingSources")]
		public Entities.TList<Entities.Role> RoleIdList
		{
			get {return _RoleIdList;}
			set 
			{
				this._RoleIdList = value;
				this.uxRoleId.DataSource = null;
				this.uxRoleId.DataSource = value;
			}
		}
		
		private bool _allowNewItemInRoleIdList;
		
		/// <summary>
		/// Indicates if the ComboBox associated with the RoleId property allow user to add item.
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInRoleIdList
		{
			get { return _allowNewItemInRoleIdList;}
			set
			{
				this._allowNewItemInRoleIdList = value;
				this.uxRoleId.DropDownStyle = value ? System.Windows.Forms.ComboBoxStyle.DropDown : System.Windows.Forms.ComboBoxStyle.DropDownList;
			}
		}
		
				
		private Entities.TList<Entities.Department> _DeptIdList;
		
		/// <summary>
		/// The ComboBox associated with the DeptId property.
		/// </summary>
		[System.ComponentModel.Category("ComboBox BindingSources")]
		public Entities.TList<Entities.Department> DeptIdList
		{
			get {return _DeptIdList;}
			set 
			{
				this._DeptIdList = value;
				this.uxDeptId.DataSource = null;
				this.uxDeptId.DataSource = value;
			}
		}
		
		private bool _allowNewItemInDeptIdList;
		
		/// <summary>
		/// Indicates if the ComboBox associated with the DeptId property allow user to add item.
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInDeptIdList
		{
			get { return _allowNewItemInDeptIdList;}
			set
			{
				this._allowNewItemInDeptIdList = value;
				this.uxDeptId.DropDownStyle = value ? System.Windows.Forms.ComboBoxStyle.DropDown : System.Windows.Forms.ComboBoxStyle.DropDownList;
			}
		}
		
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	}
}
